home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / hc2_x / tcprogud.sit / TC Prog Guide / card_36371.txt < prev    next >
Text File  |  1991-02-27  |  1KB  |  24 lines

  1. -- card: 36371 from stack: in
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 4755
  5. -- name: 
  6.  
  7.  
  8. -- part contents for background part 4
  9. ----- text -----
  10. DERIVED CLASSES
  11.  
  12. An important object-oriented technique is that of deriving new classes from existing classes.  A derived class (descendant, child or subclass) is one which INHERITS the instance variable and method declarations of the base class (ancestor, parent or superclass), and adds instance variables and methods of its own.  In C++, methods are inherited only if the original declaration uses the 'virtual' keyword.  A derived class may also provide new definitions for the methods declared in the base class, in which case the new definition is said to "override" the original.  The syntax to derive the Student class from the Person class is:
  13.  
  14.     struct  Student:Person
  15.     {
  16.         int    student_num;    /* additional instance variable */
  17.         
  18.         void    set(void);         /* override original set() method */
  19.         void    print(void);    /* override original print() method */
  20.     };
  21.  
  22. -- part contents for background part 7
  23. ----- text -----
  24. 108